import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.image.ImageObserver;

/**
 * This class is a simple superclass for the basic game elements in Space Invaders.
 * It simply exists to provide a simple way to handle collisions.
 * @author Chris
 *
 */
public abstract class GameObject {

	protected int x_position;
	protected int y_position;
	protected int width;
	protected int height;
	protected int image_index;
	Sprite sprite;
	
	GameObject(int x, int y, Sprite sprite){
		x_position = x;
		y_position = y;
		this.width = sprite.image_width;
		this.height = sprite.image_height;
		this.sprite = sprite;
		image_index = 0;
	}
	
	public int getWidth(){
		return width;
	}
	public int getHeight(){
		return height;
	}
	/**
	 * @return a rectangle representing the collision bounds of this object.
	 * In calculating the vertices, this method assumes that the image is centered 
	 * (thus using x - width/2 instead of x)
	 */
	public Rectangle getRect(){
		return new Rectangle(x_position-width/2, y_position-height/2, width, height);
	}
	
	public void draw(Graphics g, ImageObserver io){
		g.drawImage(sprite.getFrame(image_index), x_position-sprite.image_width/2, y_position-sprite.image_height/2, io);
//		g.setColor(Color.GREEN);
//		g.fillRect(x_position-1, y_position-1, 2, 2);
	}
}
